﻿using System;
using System.Data;
using LibDBConnect;


namespace LibDataLayer
{
    public static class DalTopics
    {
        private static readonly SqlHelper Cls = new SqlHelper();
        #region[Get-Data]
        public static DataTable GetTopics(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            return Cls.GetData("sp_Topics_Get");
        }
        public static DataTable GetTopicsEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", id);
            return Cls.GetData("sp_Topics_Get_Edit");
        }
        public static DataTable GetTopicsFillterStatus(int IsActive)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("IsActive", IsActive);
            return Cls.GetData("sp_Topics_Get_FillterStatus");
        }
        public static DataTable GetTopicsFillterCategories(int Fid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Fid", Fid);
            return Cls.GetData("sp_Topics_Get_FillterCategories");
        }
        public static DataTable GetTopicsFid(int Fid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Fid", Fid);
            return Cls.GetData("sp_Forum_Get_HomePage_Fid");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("UserId", obj.UserId);
            Cls.AddParameter("Subject", obj.Subject);
            Cls.AddParameter("Posted", obj.Posted);
            Cls.AddParameter("NumViews", obj.NumViews);
            Cls.AddParameter("Closed", obj.Closed);
            Cls.AddParameter("Sticky", obj.Sticky);
            Cls.AddParameter("MovedTo", obj.MovedTo);
            Cls.AddParameter("Fid", obj.Fid);
            return Cls.ExecuteNonQuery("sp_Topics_Insert");
        }
        public static bool Update(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", obj.Tid);
            Cls.AddParameter("Subject", obj.Subject);
            Cls.AddParameter("NumViews", obj.NumViews);
            Cls.AddParameter("Closed", obj.Closed);
            Cls.AddParameter("Sticky", obj.Sticky);
            Cls.AddParameter("MovedTo", obj.MovedTo);
            Cls.AddParameter("Fid", obj.Fid);
            return Cls.ExecuteNonQuery("sp_Topics_Update");
        }
        public static bool Delete(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", obj.Tid);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Topics_Delete", "@Msg");
            return true;
        }
        public static bool UpdateCheck(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", obj.Tid);
            Cls.AddParameter("IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_Topics_Update_Check");
        }
        public static bool UpdateNumView(DTOTopics obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("Tid", obj.Tid);
            Cls.AddParameter("NumViews", obj.NumViews);
            return Cls.ExecuteNonQuery("sp_Update_Topics_NumView");
        }
        #endregion

        #region[Get-Data-HomePage]
        public static DataTable GetTopicsHomePage(string keywords,int Fid)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("KEYWORDS", keywords);
            Cls.AddParameter("Fid", Fid);
            return Cls.GetData("sp_Topics_Get_HomePage");
        }
        #endregion
    }
    public class DTOTopics
    {
        public string UserId { get; set; }
        public int ? Tid { get; set; }
        public string Subject { get; set; }
        public DateTime Posted { get; set; }
        public int ? NumViews { get; set; }
        public int ? Closed { get; set; }
        public int ? Sticky { get; set; }
        public int ? MovedTo { get; set; }
        public int ? Fid { get; set; }
        public bool IsActive { get; set; }
        public int Msg { get; set; }
        public string Message { get; set; }
    }
}